package com.heima.wemedia.controller.v1;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelPageDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 频道信息表 前端控制器
 * </p>
 *
 * @author azl
 * @since 2025-04-06
 */
@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;
    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult findAll() {
        log.info("查询所有频道");
        return wmChannelService.findAll();
    }

    /**
     * 频道名称模糊分页查询
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelPageDto dto){
        log.info("频道名称模糊分页查询:{}",dto);
        return wmChannelService.listPage(dto);
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        log.info("新增频道:{}",wmChannel);
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult delChannel(@PathVariable("id") Integer id){
        log.info("删除频道:{}",id);
        return wmChannelService.delChannel(id);
    }


}
